package com.course.server.impl;

import com.course.dto.CourseDTO;
import com.course.dto.PageBean;
import com.course.entity.Course;
import com.course.mapper.CourseMapper;
import com.course.server.CourseService;
import com.course.vo.CourseList;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Resource
    CourseMapper courseMapper;
    /**
     * 添加新的课程
     * @param courseDTO
     */
    @Override
    public void addCourse(CourseDTO courseDTO) {
        courseMapper.insert(courseDTO);
    }

    /**
     * 根据课程号查询课程
     * @param cno
     * @return
     */
    public List<Course> SearchByCno(String cno){
        List<Course> CourseList=courseMapper.SearchByCno(cno);
        return CourseList;
    }

    /**
     * 根据课程号删除课程
     * @param cno
     */
    @Override
    public void deleteByCno(String cno) {
        //调用mapper层去删除课程
        courseMapper.deleteByCno(cno);
    }

    /**
     * 更新课程信息
     * @param courseDTO
     */
    @Override
    public void update(CourseDTO courseDTO) {
        courseMapper.update(courseDTO);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String cno, String cname,String tno) {
        Page<CourseDTO> coursePage= PageHelper.startPage(page,pageSize);
        coursePage=(Page<CourseDTO>) courseMapper.page(cno,cname,tno);
        //封装成pageBean返回给前端
        PageBean pageBean=new PageBean(coursePage.getTotal(),coursePage.getResult());
        return pageBean;
    }

    @Override
    public List<CourseList> allCourse() {
        List<CourseList> courseList=courseMapper.allCourse();
        return courseList;
    }

}
